package com.jyxd.web.mq;

import cn.hutool.core.lang.Snowflake;
import com.jyxd.web.data.basic.NurseRecordForm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Component
public class TemperatureSheetSender {

    private final Logger logger = LoggerFactory.getLogger(TemperatureSheetSender.class);
    private final AmqpTemplate rabbitTemplate;

    @Value("${icu.job.mq.temperature-sheet-update.routingKey}")
    private String routingKey;
    @Value("${icu.job.mq.temperature-sheet-update.exchange}")
    private String exchange;
    private final Snowflake snowflake;

    public TemperatureSheetSender(RabbitTemplate rabbitTemplate, Snowflake snowflake) {
        this.rabbitTemplate = rabbitTemplate;
        this.snowflake = snowflake;
    }

    public void send(NurseRecordForm nurseRecordForm) {
        logger.info("nurseRecordForm:{}", nurseRecordForm);
        rabbitTemplate.convertAndSend(exchange, routingKey, nurseRecordForm, message -> {
            message.getMessageProperties().setMessageId(snowflake.nextIdStr());
            return message;
        });
    }
}